home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 4
/
Mac Giga-ROM 4.0 - 1993.toast
/
FILES
/
DEV
/
A-B
/
Acius09:92.cpt
/
Acius09_92
/
TN 30ƒ
/
Ext4D_LineStarts.p
< prev
next >
Wrap
Text File
|
1992-09-30
|
9KB
|
369 lines
{===================================================================================================}
{
Text to array external commands for 4th DIMENSION 2.x.x
by Dominique Hermsdorff
©1991 ACI,ACIUS Inc.
To work with this source code, you have to be familiar with the Text Edit Manager, see the
relevant Inside Macintosh volumes in this purpose.
About the Line Starts external commands...
These commands and the source code are provided to you for your information.
They are intended to help you in the implementation of your own external commands.
They are not intended to be used as is, in final applications.
If you would like to use these commands inside your applications, please use,
or contact a developer able to use, the source code provided as a template
to build your own commands.
Note: ACI and ACIUS Technical Support do not provide support for these external commands.
}
{===================================================================================================}
UNIT Ext4D_LineStarts;
{$IFC Undefined THINK_PASCAL }
{$D- }
{$R- }
{$ENDC }
INTERFACE
{$IFC Undefined THINK_PASCAL }
Uses MemTypes,
QuickDraw,
OSIntf,
ToolIntf,
PackIntf,
Events,
SysEqu,
Traps,
Ext4DIntf;
{$ENDC}
{$IFC Undefined THINK_PASCAL }
{$SETC DebugOn = TRUE }
{$IFC DebugOn }
{$D+ }
{$R+ }
{$ELSEC }
{$D- }
{$R- }
{$ENDC }
{$ENDC }
{$IFC UNDEFINED THINK_PASCAL }
{$R- }
{$ENDC }
PROCEDURE CALL_LINESTARTSPACK(ProcNum:LongInt;Params:ParamsTabPtr;Var Data:Handle;Var FuncPtr:Ptr);
IMPLEMENTATION
CONST kLineStarts = 1;
kGETFONTINFO = 2;
kErrTextIsEmpty = 1;
kErrThisIsNotaText = 2;
kErrBadSize = 3;
kErrWasExpectingAnArrayOfLong = 4;
kErrWidthIsTooSmall = 5;
OKButton = 1;
DevToolDlgID = 0;
PROCEDURE LINESTARTSPACK(ProcNum:LongInt;Params:ParamsTabPtr;Var PackData:Handle;Var FuncPtr:Ptr);FORWARD;
PROCEDURE CALL_LINESTARTSPACK(ProcNum:LongInt;Params:ParamsTabPtr;Var Data:Handle;Var FuncPtr:Ptr);
BEGIN
LINESTARTSPACK(ProcNum,Params,Data,FuncPtr);
END; { CALL_LINESTARTSPACK }
FUNCTION Integer2Style(Style4D:Integer):Style; InLine $301F,$7208,$E368,$3E80; { MOVE.W (A7)+,D0
MOVEQ #$08,D1
LSL.W D1,D0
MOVE.W D0,(A7) }
PROCEDURE MySetCursor(WhichCursor:INTEGER);
BEGIN
SetCursor(GetCursor(GetResNum('4BNX','CURS',WhichCursor))^^);
END; { MySetCursor }
{$I Ext4D_DevTools_Dlg.p }
PROCEDURE Clear4DArray(anArray:VarRecPtr);
VAR z:LongInt;
h:Handle;
s:StringPtr;
BEGIN
WITH anArray^ DO
BEGIN
IF NbElem>0 THEN
BEGIN
IF VarKind=TabAlpha THEN
BEGIN
IF TabAlphaH<>NIL THEN
BEGIN
FOR z:=0 TO NbElem DO
BEGIN
h:=Handle(TabAlphaH^^[z].CC);
IF h<>NIL THEN DisposHandle(h);
END;
END;
END
ELSE
BEGIN
IF VarKind=TabPict THEN
BEGIN
FOR z:=0 TO NbElem DO
BEGIN
h:=Handle(TabPictH^^[z]);
IF h<>NIL THEN DisposHandle(h);
END;
END;
END;
CASE VarKind OF
TabInt : z:=SizeOf(Integer);
TabLong : z:=SizeOf(LongInt);
TabNum : z:=SizeOf(Extended);
TabAlpha : z:=SizeOf(TE4D);
TabPict : z:=SizeOf(PicHandle);
TabDate : z:=SizeOf(Date4D);
TabBool : z:=2;
TabStrFix : BEGIN
z:=ORD4(TabFixH^^.LenFix);
IF ODD(z) THEN z:=z+1;
z:=z+2;
END;
END;
IF TabIntH<>NIL THEN SetHandleSize(Handle(TabIntH),z);
NbElem:=0;
CurSel:=0;
CASE VarKind OF
TabBool,
TabInt : TabIntH^^[0]:=0;
TabLong : TabLongH^^[0]:=0;
TabNum : TabNumH^^[0]:=0;
TabAlpha : WITH TabAlphaH^^[0] DO
BEGIN
Len:=0;
CC:=NIL;
END;
TabPict : TabPictH^^[0]:=NIL;
TabDate : WITH TabDateH^^[0] DO
BEGIN
Day:=0;
Month:=0;
Year:=0;
END;
TabStrFix : BEGIN
s:=StringPtr(ORD4(TabFixH^)+2);
s^:='';
END;
END;
END;
END;
END; { Clear4DArray }
FUNCTION Resize4DArray(anArray:VarRecPtr;Nb:LongInt):INTEGER;
TYPE IntegerHandle = ^IntegerPtr;
VAR n:INTEGER;
z:LongInt;
h:Handle;
BEGIN
Resize4DArray:=NoErr;
Clear4DArray(anArray);
WITH anArray^ DO
BEGIN
Nb:=Nb+1;
CASE VarKind OF
TabInt : z:=Nb*SizeOf(INTEGER);
TabLong : z:=Nb*SizeOf(LongInt);
TabNum : z:=Nb*SizeOf(Extended);
TabAlpha : z:=Nb*SizeOf(TE4D);
TabPict : z:=Nb*SizeOf(PicHandle);
TabDate : z:=Nb*SizeOf(Date4D);
TabBool : z:=2+(Nb DIV 8);
TabStrFix : BEGIN
n:=TabFixH^^.LenFix;
z:=ORD4(n);
IF ODD(z) THEN z:=z+1;
z:=2+(Nb*z);
END;
END;
Nb:=Nb-1;
h:=NewHandleClear(z);
IF h<>NIL THEN
BEGIN
IF TabIntH<>NIL THEN DisposHandle(Handle(TabIntH));
TabIntH:=TabOfIntHandle(h);
NbElem:=Nb;
CurSel:=0;
IF VarKind=TabStrFix THEN IntegerHandle(TabFixH)^^:=n;
END
ELSE Resize4DArray:=MemFullErr;
END;
END; { Resize4DArray }
FUNCTION FontNameToFontID(NameOfFont:StringPtr):INTEGER;
VAR I:INTEGER;
L:LongInt;
BEGIN
IF Length(NameOfFont^)>0 THEN
BEGIN
IF NameOfFont^[1]='#' THEN
BEGIN
StringToNum(COPY(NameOfFont^,2,Length(NameOfFont^)-1),L);
FontNameToFontID:=ORD(L);
END
ELSE
BEGIN
GetFNum(NameOfFont^,I);
FontNameToFontID:=I;
END;
END
ELSE FontNameToFontID:=0;
END; { FontNameToFontID }
PROCEDURE LINESTARTSPACK;
FUNCTION DoLINESTARTS(TheText:Te4DPtr;TheFont:StringPtr;
TheSize,TheStyle,TheWidth:INTEGER;ThePositions:VarRecPtr):INTEGER;
VAR ErrCode,Len,Count:INTEGER;
MyTE:TEHandle;
H:Handle;
CurPort:GrafPtr;
MyRect:Rect;
MyFont:FontInfo;
MyPort:GrafPort;
BEGIN
ErrCode:=NoErr;
IF (0<TheSize) & (TheSize<=255) THEN
BEGIN
IF ThePositions^.VarKind=TabLong THEN
BEGIN
IF TheText^.Len>=0 THEN
BEGIN
IF TheText^.CC<>NIL THEN
BEGIN
Len:=ORD(GetHandleSize(Handle(TheText^.CC)));
IF Len>0 THEN
BEGIN
Clear4DArray(ThePositions);
GetPort(CurPort);
OpenPort(@MyPort);
WITH MyPort DO
BEGIN
SetEmptyRgn(ClipRgn);
SetEmptyRgn(VisRgn);
END;
TextFont(FontNameToFontID(TheFont));
TextSize(TheSize);
TextFace(Integer2Style(TheStyle));
GetFontInfo(MyFont);
IF TheWidth>MyFont.widMax THEN
BEGIN
SetRect(MyRect,0,0,TheWidth,342);
MyTE:=TENew(MyRect,MyRect);
IF MyTE<>NIL THEN
BEGIN
H:=MyTE^^.hText;
MyTE^^.hText:=Handle(TheText^.CC);
TECalText(MyTE);
MyTE^^.hText:=H;
ErrCode:=Resize4DArray(ThePositions,ORD4(1+MyTE^^.nLines));
IF ErrCode=NoErr THEN
BEGIN
FOR Count:=1 TO (MyTE^^.nLines+1) DO
ThePositions^.TabLongH^^[Count]:=1+MyTE^^.LineStarts[Count-1];
END;
TEDispose(MyTE);
END
ELSE ErrCode:=MemFullErr;
END
ELSE
BEGIN
TheWidth:=MyFont.WidMax;
ErrCode:=kErrWidthIsTooSmall;
END;
SetPort(CurPort);
ClosePort(@MyPort);
END
ELSE ErrCode:=kErrTextIsEmpty;
END
ELSE ErrCode:=kErrTextIsEmpty;
END
ELSE ErrCode:=kErrThisIsNotaText;
END
ELSE ErrCode:=kErrWasExpectingAnArrayOfLong;
END
ELSE ErrCode:=kErrBadSize;
DoLINESTARTS:=ErrCode;
END; { DoLINESTARTS }
PROCEDURE DoGetFontInfo(TheFont:StringPtr;TheSize,TheStyle:INTEGER;
VAR FAscent,FDescent,FLeading,FWidMax:LongInt);
VAR CurPort:GrafPtr;
MyFont:FontInfo;
MyPort:GrafPort;
BEGIN
GetPort(CurPort);
OpenPort(@MyPort);
TextFont(FontNameToFontID(TheFont));
TextSize(TheSize);
TextFace(Integer2Style(TheStyle));
GetFontInfo(MyFont);
WITH MyFont DO
BEGIN
FAscent:=ORD4(Ascent);
FDescent:=ORD4(Descent);
FLeading:=ORD4(Leading);
FWidMax:=ORD4(WidMax);
END;
SetPort(CurPort);
ClosePort(@MyPort);
END; { DoGetFontInfo }
BEGIN { LINESTARTSPACK }
IF ProcNum>0 THEN
BEGIN
CASE ProcNum OF
{ Line starts(Text;Font;FontSize;FontStyle;Width;Positions) -> OS Error
Line starts(&T;&S;&L;&L;&L;&X):L }
kLineStarts:
FuncPtr:=Ptr(ORD4(DoLINESTARTS(Te4DPtr(Params^[1]),
StringPtr(Params^[2]),
ORD(LongIntPtr(Params^[3])^),
ORD(LongIntPtr(Params^[4])^),
ORD(LongIntPtr(Params^[5])^),
VarRecPtr(Params^[6]))));
{ GET FONT INFO(Font;FontSize;FontStyle;FAscent;FDescent;FLeading;FWidMax)
GET FONT INFO(&S;&L;&L;&L;&L;&L;&L) }
kGetFontInfo:
DoGetFontInfo(StringPtr(Params^[1]),
ORD(LongIntPtr(Params^[2])^),
ORD(LongIntPtr(Params^[3])^),
LongIntPtr(Params^[4])^,
LongIntPtr(Params^[5])^,
LongIntPtr(Params^[6])^,
LongIntPtr(Params^[7])^);
END; { CASE ProcNum OF }
END
ELSE IF ProcNum=Init4DPackage THEN ShowDevToolDlg;
END; { LINESTARTSPACK }
END. { UNIT Ext4D_LineStarts }